<?php namespace Admin\Controller; 

use Hdphp\Controller\Controller;

//后台——首页控制器
class IndexController extends CommonController{
	
	private $admin_model;
	//HdPHP自定义构造函数
	public function __init()
	{
		//调用CommonController里的构造函数
		parent::__init();
		//实例化admin模型
		$this->admin_model = new \Common\Model\Admin;
	}
	
    //动作
    public function index(){
    	
       View::make();
    }
	//欢迎页
	public function welcome(){
       View::make();
    }
	//修改密码
	public function changPwd(){
		if(IS_POST){
		    //p(Q("post."));
		    //接收数据
		    $new_password = Q('post.new_password');
			$confirm_password = Q('post.confirm_password');
			//判断旧密码是否正确
		    $data = $this->admin_model->where("admin_id=" . $_SESSION['admin_id'])->find();
			//p($data);
			if($data['password'] != Q('post.oldPwd','','md5')) View::error('旧密码错误');
			//更新密码
			$this->admin_model->where("admin_id={$_SESSION['admin_id']}")->save(array('password'=>md5($new_password)));
			View::success('修改成功',U('Admin/index'));
		}
		View::make();
	}
}












